pub fn update_lockfile(manifest_path: &Path,
opts: &UpdateOptions) -> CargoResult<()> {
- let package = try!(Package::for_path(manifest_path, opts.config));
-
- let previous_resolve = match try!(ops::load_pkg_lockfile(&package,
- opts.config)) {
- Some(resolve) => resolve,
- None => bail!("a Cargo.lock must exist before it is updated")
- };
if opts.aggressive && opts.precise.is_some() {
bail!("cannot specify both aggressive and precise simultaneously")
}
+ let package = try!(Package::for_path(manifest_path, opts.config));
+
+ let previous_resolve = match try!(ops::load_pkg_lockfile(&package, opts.config)) {
+ Some(resolve) => resolve,
+ None => {
+ let _ = generate_lockfile(manifest_path, opts.config);
+ return Ok(());
+ }
+ };
let mut registry = PackageRegistry::new(opts.config);
let mut to_avoid = HashSet::new();
-use std::fs::File;
+use std::fs::{self, File};
use std::io::prelude::*;
use support::{project, execs};
-use hamcrest::{assert_that, existing_file};
+use hamcrest::{assert_that, existing_file, is_not};
fn setup() {}
assert!(lock2.starts_with("[root]\r\n"));
assert_eq!(lock1, lock2);
});
+
+test!(cargo_update_generate_lockfile {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ authors = []
+ version = "0.0.1"
+ "#)
+ .file("src/main.rs", "fn main() {}");
+
+ let lockfile = p.root().join("Cargo.lock");
+ assert_that(&lockfile, is_not(existing_file()));
+ assert_that(p.cargo_process("update"), execs().with_status(0).with_stdout(""));
+ assert_that(&lockfile, existing_file());
+
+ fs::remove_file(p.root().join("Cargo.lock")).unwrap();
+
+ assert_that(&lockfile, is_not(existing_file()));
+ assert_that(p.cargo("update"), execs().with_status(0).with_stdout(""));
+ assert_that(&lockfile, existing_file());
+
+});